package com.chao.ServerSocket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import java.net.Socket;

public class Client {
    static final int PORT=1111;
    public static void main(String[] args) throws IOException, InterruptedException {
        Socket client=new Socket();
        InetSocketAddress address = new InetSocketAddress("localhost", PORT);
        client.connect(address);
        InputStream in = client.getInputStream();
        System.out.println("建立连接："+client.getRemoteSocketAddress());
        InputStreamReader reader=new InputStreamReader(in,"ASCII");
        BufferedReader br=new BufferedReader(reader);
        while (true){
            String line = null;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
            if(line.equals("bye")) break;
            Thread.sleep(1000);
        }
        reader.close();
        in.close();
        client.close();
    }
}
